import socket
import threading
import time
import os
import signal
import sys

#def onsignal_term(a,bh):


sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind(('', 8001))

def send_punch():
	data = '\x02'+chr(int(sys.argv[1]))
	print repr(data)
	while True:
		sock.sendto(data,('124.16.138.204',8000))
      	  	print 'send ok'
        	time.sleep(30)
        	
t = threading.Thread(target = send_punch)
t.start()

while True:
	data,addr = sock.recvfrom(8192)
	print repr(data),addr
sock.close()
